/* symbol2string.asm
 *
 * 
 */

/*

cant be done here, since must have the bucket list start address - only exist in compiler.py!!!
 
STRING2SYMBOL:
  PUSH(FP);
  MOV(FP,SP);
  PUSH(R1);
  PUSH(R2);
  
  MOV(R0, FPARG(2)); 				//R0 = sob string Pointer
  CMP(IND(R0), IMM(T_STRING));		// input check
  JUMP_NE(TYPE_ERROR);
  
  MOV(R1,IND(bucket list address));			// R1 = pointer to first bucket at bucketList
  //notice that if there are no buckets, this address will pointer to SOB_NILL!
  
  STRING2SYMBOL_SEARCH_LOOP:
  CMP(R1,IMM(T_NIL));						// if bucketlist ended (last link point to nil)
  JUMP_EQ(STRING2SYMBOL_SEARCH_NOT_FOUND);		// then there was not an existing symbol already
  CMP(R0,INDD(R1,0));						// if R1 bucket is pointing to R0 - the same sob string
  JUMP_EQ(STRING2SYMBOL_CREATE_SYM);			// then we found the string, its already has a symbol bucket
  MOV(R2,R1);								// R2 = last checked bucket (saving this incase its the last bucket, we will need the one before the last)
  MOV(R1,INDD(R1,1));						// R1 = pointer to next link in bucketList
  JUMP(STRING2SYMBOL_SEARCH_LOOP);
  
  STRING2SYMBOL_SEARCH_NOT_FOUND:			// we will create a new bucket, after last bucket
  PUSH(IMM(2));
  CALL(MALLOC);
  DROP(2);									// now R0 has the new bucket address!
  MOV(INDD(R2,1),R0);						// link last bucket to the new one
  MOV(IND(R0,0),FPARG(2));					// R0[0] = pointer to sob string - given as argument!
  MOV(IND(R0,1),IMM(2));					// R0[0] = pointer to SOB_NIL
  MOV(R1,R0);								// R1 = pointer to new bucket created
  
  STRING2SYMBOL_CREATE_SYM:					// creating the new symbol, and link it to its bucket, which address is now in R1
  PUSH(IMM(2));
  CALL(MALLOC);
  DROP(2);									// now R0 has the new symbol address!
  MOV(INDD(R0,0),T_SYMBOL);        			// R0[0] = T_SYMBOL
  MOV(INDD(R0,1),R1);        				// R0[1] = pointer to symbol's bucket, which has the symbol string representation sob_string
  
  POP(R2);
  POP(R1);
  POP(FP);
  RETURN;									// return R0 = address to new SOB_SYMBOL

  */